package co.fitstart.weapp.api.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.courseware.FitnessTag;
import co.fitstart.entity.courseware.dietary.DietaryProgramTemplate;
import co.fitstart.entity.courseware.dietary.DietaryProgramType;
import co.fitstart.entity.courseware.fitnessgroup.BatchCoursewareTemplate;
import co.fitstart.entity.courseware.fitnessgroup.BatchCoursewareType;
import co.fitstart.entity.courseware.fitnessgroup.CoursewareTemplate;
import co.fitstart.entity.courseware.fitnessgroup.DailyCoursewareTemplate;
import co.fitstart.entity.courseware.fitnessgroup.FitnessGroup;
import co.fitstart.entity.courseware.fitnessgroup.SpecialCoursewareTemplate;

/**
 * 
 * @author haiyan_xiao
 *
 */
@Dao("hibernate")
public interface CoursewareTemplateDao {

    /**
     * 
     * @param fitnessGroup
     * @param type
     * @param sorting
     * @return
     */
    @Query("FROM BatchCoursewareTemplate WHERE disabled = false AND fitnessGroup = :fitnessGroup AND type =:type AND sorting = :sorting")
    public BatchCoursewareTemplate loadBatchCoursewareTemplate(@Variable("fitnessGroup") FitnessGroup fitnessGroup, @Variable("type") BatchCoursewareType type, @Variable("sorting") int sorting);

    /**
     * 
     * @return
     */
    @Query("FROM FitnessTag WHERE disabled = false")
    public List<FitnessTag> listFitnessTag();

    /**
     * 
     * @param tagIds
     * @return
     */
    @Query("FROM FitnessTag WHERE disabled = false AND id IN (:tagIds)")
    public List<FitnessTag> listFitnessTag(@Variable("tagIds") List<Long> tagIds);

    /**
     * 
     * @param fitnessGroup
     * @param type
     * @return
     */
    @Query("FROM BatchCoursewareTemplate WHERE disabled = false AND fitnessGroup = :fitnessGroup AND type = :type ORDER BY sorting ASC")
    public List<BatchCoursewareTemplate> listBatchCoursewareTemplate(@Variable("fitnessGroup") FitnessGroup fitnessGroup, @Variable("type") BatchCoursewareType type);

    /**
     * 
     * @param fitnessGroup
     * @param type
     * @param maxSorting
     * @return
     */
    @Query("FROM BatchCoursewareTemplate WHERE disabled = false AND fitnessGroup = :fitnessGroup AND type = :type AND sorting <= :maxSorting ORDER BY sorting ASC")
    public List<BatchCoursewareTemplate> listBatchCoursewareTemplate(@Variable("fitnessGroup") FitnessGroup fitnessGroup, @Variable("type") BatchCoursewareType type, @Variable("maxSorting") int maxSorting);

    /**
     * 
     * @param batch
     * @return
     */
    @Query("FROM DailyCoursewareTemplate WHERE disabled = false AND batch = :batch ORDER BY sorting")
    public List<DailyCoursewareTemplate> listDailyCoursewareTemplate(@Variable("batch") BatchCoursewareTemplate batch);

    /**
     * 
     * @param dailyCoursewareTemplate
     * @return
     */
    @Query("FROM CoursewareTemplate WHERE disabled = false AND daily = :daily ORDER BY id")
    public List<CoursewareTemplate> listCoursewareTemplate(@Variable("daily") DailyCoursewareTemplate dailyCoursewareTemplate);

    /**
     * 
     * @param type
     * @return
     */
    @Query("FROM DietaryProgramTemplate WHERE disabled = false AND type = :type")
    public List<DietaryProgramTemplate> listDietaryTemplate(@Variable("type") DietaryProgramType type);

    /**
     * 
     * @param fitnessGroup
     * @return
     */
    @Query("FROM SpecialCoursewareTemplate WHERE disabled = false AND fitnessGroup = :fitnessGroup")
    public SpecialCoursewareTemplate loadSpecialCoursewareTemplate(@Variable("fitnessGroup") FitnessGroup fitnessGroup);

    /**
     * 
     * @param specialCoursewareTemplate
     * @return
     */
    @Query("FROM CoursewareTemplate WHERE disabled = false AND special = :special ORDER BY id")
    public List<CoursewareTemplate> listCoursewareTemplate(@Variable("special") SpecialCoursewareTemplate specialCoursewareTemplate);
}
